package com.ziyun.erp.modules.facilitator.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.ziyun.erp.modules.facilitator.entity.AuditVo;
import com.ziyun.erp.modules.facilitator.entity.FacilitatorEntity;
import com.ziyun.erp.modules.facilitator.entity.FacilitatorVo;
import com.ziyun.erp.modules.facilitator.entity.FacilitatorStatisticVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 团队表
 * 
 * @author jiangli
 * @email 
 * @date 2018-12-29 16:20:17
 */
public interface FacilitatorDao extends BaseMapper<FacilitatorEntity> {

    List<FacilitatorEntity> list(@Param("page")Pagination page,@Param("map") Map<String, Object> map);

    @Select("SELECT a.team_id,a.team_name,a.legal_name,a.id_card_urls,a.business_url,b.nickname,b.mobile,a.agreement_url,a.user_id,a.del_flag,a.createtime FROM user_team a LEFT JOIN user_base_info b ON a.user_id=b.user_id  WHERE a.source_type='facilitator' AND a.audit_status=1 AND a.team_id=#{teamId}")
    FacilitatorEntity getFacilitatorEntity(Integer teamId);

    @Select("SELECT DISTINCT `area` FROM seller_info WHERE seller_id IN (SELECT seller_id FROM facilitator_seller_relation WHERE disabled=0 AND audit_status=1 AND parent_user_id =#{userId})")
    List<String> getareasByUserId(Integer userId);

    @Select("SELECT seller_name FROM seller_info a LEFT JOIN facilitator_seller_relation b USING(seller_id) WHERE b.parent_user_id=#{userId} AND b.audit_status=1 AND b.disabled=0")
    List<String> getShopsByUserId(Integer userId);

    List<AuditVo> getAuditVo(@Param("map") Map<String, Object> map);

    List<FacilitatorVo> facilitatorData(@Param("map") Map<String, Object> map);

    List<Map<String,Object>> facilitatorList();

    List<Map<String,Object>> userDistributionList(Integer teamId);

    List<FacilitatorStatisticVo> facilitatorStatisticVo(@Param("page")Pagination page,@Param("map") Map<String, Object> map);
    //查所有不分页,用于统计
    List<FacilitatorStatisticVo> facilitatorStatisticVo(@Param("map") Map<String, Object> map);

 }
